package com.shengyo.model.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.shengyo.model.bean.Pscore;
import com.shengyo.model.dao.IPscoreDAO;

public class PscoreDAOImpl extends BaseDAOImpl implements IPscoreDAO{

	
	public void delete(Pscore pscore) {
		this.getHibernateTemplate().delete(pscore);
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Pscore> findAll() {
		return this.getHibernateTemplate().find("from pscore");
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Pscore> findAll(final int first, final int max) {
		return this.getHibernateTemplate().executeFind(new HibernateCallback(){

			
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				return session.createQuery("from pscore").setFirstResult(first).setMaxResults(max).list();
			}
			
		});
	}

	public Object findById(int id) {
		return this.getHibernateTemplate().load(Pscore.class, id);
	}
	
	public static void main(String[] args) {
		PscoreDAOImpl tagImpl = new PscoreDAOImpl();
		Pscore tag = new Pscore(1,1,1,1,1);
		tagImpl.save(tag);
		/*TagDAOImpl tagImpl = new TagDAOImpl();
		Tag tag=(Tag) tagImpl.findById(1);
		System.out.print(tag.toString());
		*/
	}
}
